/**
 * @author 太阳当空丶赵
 * @date 2022/11/28-20:48
 * @version 1.0.0
 * index.js
 */
const express = require('express')
// const https = require('https');
// const http = require('http');
// const fs = require('fs');
// const path = require('path')
const cors = require("cors");

const ExceptionHandling = require("./middlewore/ExceptionHandling")
const jwt = require("./middlewore/jsonWebToken")

const feedbackRouter = require('./router/feedbackRouter')
const fileRouter = require("./router/fileRouter")
const adminRouter = require("./router/adminRouter")
const userRouter = require("./router/userRouter")
//
require("./utils/banner")

//同步读取密钥和签名证书
// const options = {
//     key:fs.readFileSync(path.join(__dirname,'./utils/https/server.key')),
//     cert:fs.readFileSync(path.join(__dirname,'./utils/https/server.crt'))
// }

const app = express()
// const httpsServer = https.createServer(options,app);
// const httpServer = http.createServer(app);

app.use(jwt)
app.use(express.urlencoded({ extended: false,limit: '10mb'}));
app.use(express.json({limit: '10mb'}));
app.use(cors());

app.use("/public", express.static("./static"))
app.use("/file",fileRouter)
app.use("/admin",adminRouter)
app.use("/user",userRouter)
app.use("/feedback",feedbackRouter)
// 将 / 重定向为 user/index
/*错误处理中间件（同步）*/
app.use(ExceptionHandling)

function bootstrap(){
    const port = process.env.PORT || 80
    // httpServer.listen(port)
    // httpsServer.listen(443)
    app.listen(port, () => {
        console.log(`server running at: http://127.0.0.1:${port}`)
    })
}
bootstrap()
